package leetcode.code0901;

public class StockSpanner2 {

	int[] nums;
	int[] spans;
	int p;

	public StockSpanner2() {
		nums = new int[10000];
		spans = new int[10000];
		p = 0;
	}

	public int next(int price) {
		nums[p] = price;
		spans[p] = 1;
		int L = p;
		while (L >= 0 && price >= nums[L]) {
			L = L - spans[L];
		}
		spans[p] = p - L;
		return spans[p++];
	}

	public static void main(String[] args) {
		StockSpanner2 S = new StockSpanner2();
		S.next(100);
		S.next(80);
		S.next(60);
		S.next(70);
		S.next(60);
		S.next(75);
		S.next(85);

	}

}
